package com.jianyun.jyzs.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.jianyun.jyzs.utils.HttpResultFmVO;
import com.jianyun.jyzs.utils.PathUtil;
import com.jianyun.jyzs.utils.SysConstant2;
import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.io.File;

public abstract class ReceiveFragment extends Fragment {
    public ImageLoader imageLoader;

    /**
     * http回调方法
     */
    public abstract void onReceiveHttp(HttpResultFmVO res);

    /**
     * 广播回调方法
     *
     * @param context
     * @param intent
     */
    public abstract void onReceiveBroadCast(Context context, Intent intent);

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        //在调用时,各类图片的路径内容:
        /*
		String imageUri = "http://site.com/image.png"; // from Web
		String imageUri = "file:///mnt/sdcard/image.png"; // from SD card
		String imageUri = "content://media/external/audio/albumart/13"; // from content provider
		String imageUri = "assets://image.png"; // from assets
		String imageUri = "drawable://" + R.drawable.image; // from drawables (only images, non-9patch)
		 */
        imageLoader = ImageLoader.getInstance();
        if (SysConstant2.width > 0) {
            if (!imageLoader.isInited()) {
                File cacheDir = new File(PathUtil.imagePathName);
                ImageLoaderConfiguration config = new
                        ImageLoaderConfiguration.Builder(this.getActivity())
//								.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
//								.memoryCacheExtraOptions(240, 400) // default = device screen dimensions
                        .memoryCacheExtraOptions(Double.valueOf(SysConstant2.width / 2.5).intValue(), Double.valueOf(SysConstant2.height / 3).intValue())
                        .threadPoolSize(3)
                        .threadPriority(Thread.MIN_PRIORITY - 2)
                        .denyCacheImageMultipleSizesInMemory()
                        .discCache(new UnlimitedDiscCache(cacheDir)) // 你可以传入自己的磁盘缓存
                        .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
                        .build();
                // Initialize ImageLoader with configuration.
                ImageLoader.getInstance().init(config);
                imageLoader = ImageLoader.getInstance();
            }
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onStop() {
        super.onStop();
    }
}
